<?php

namespace App\Models;

use Dcat\Admin\Models\Administrator;
use Dcat\Admin\Traits\HasDateTimeFormatter;

use Illuminate\Database\Eloquent\Model;

class NaturalSpelling extends Model
{
    use HasDateTimeFormatter;
    protected $table = 'natural_spelling';
    protected $fillable = ['mechanism_id','name','data','book_id', 'unit_id'];

    public function setDataAttribute($value)
    {
        $this->attributes['data'] = json_encode($value);
    }

    public function getDataAttribute($value)
    {
        return json_decode($value, true);
    }

    public function mechanism()
    {
        return $this->belongsTo(Administrator::class, 'mechanism_id');
    }
}
